/*
package com.redis.Web;

import com.redis.Service.ShopBiz;
import com.redis.vo.ShopEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import redis.clients.jedis.Jedis;
import sun.plugin2.main.client.WMozillaServiceDelegate;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

//秒杀
@Controller
@RequestMapping("/jsp")
public class SpikeWeb {
    @Resource
    private ShopBiz shopBiz;
    Jedis jedis;

    //查询商品库存
    @PostMapping("/spikeshop")
    public String queryNum(HttpServletRequest request, HttpSession session) {
        int shopId = Integer.parseInt(request.getParameter("shopId"));
        //查询商品 返回实体
        ShopEntity shopEntity = shopBiz.shopNum(shopId);
        System.out.println(shopEntity.getShopId());
        //获取库存数量---
        //输出
        System.out.println(jedis.get(String.valueOf(shopId)));
        String key = String.valueOf(shopId);
        //获取value 并赋值
        String value = jedis.get(key);
        int num = -1;
        if (value == null) {
            num = shopEntity.getShopNumber();
            jedis.set(key, String.valueOf(num));
        } else {
            num = Integer.parseInt(value);
        }

        int shopNumber = num;
        System.out.println(shopEntity.getShopNumber());
        System.out.println(num+"-------");
        if (shopNumber >= 0) {
            //此时秒杀成功 库存-1
            jedis.decr(String.valueOf(shopId));
            System.out.println(jedis.get(key));
            jedis.expire(key, 60);
            //同步更新数据库信息 ->数量-1
            shopBiz.updateNumber(shopId);
                //添加userId userName 到spikeList
            String userName= (String) session.getAttribute("username");
            int userId= (int) session.getAttribute("userid");
            System.out.println(userName);
            jedis.zadd("spikeList",userId,userName);
            //同步添加到数据库
            int i=shopBiz.insertSpike(shopId,userId,userName);
            System.out.println("i="+i);
            return "logok";
        } else
            return "logno";
    }
}
*/
